package name.luoyong.shiro.shiroIniCustom.filter.print;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.web.filter.AccessControlFilter;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;

public class PrintCacheFilter extends AccessControlFilter {

	@Override
	protected boolean isAccessAllowed(ServletRequest request,
			ServletResponse response, Object mappedValue) throws Exception {
		/*
		DefaultWebSecurityManager sm = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager();
		MyCacheManager cm = (MyCacheManager) sm.getCacheManager();
		Map<Object,Cache> cachesMap = cm.allCaches();
		Set<Entry<Object,Cache>> setEntryCache = cachesMap.entrySet();
		
		System.out.println("-------- printAllCaches() ------");
		for(Entry<Object,Cache> entry : setEntryCache) {
			System.out.println(entry.getKey()+" : ");
			Cache cache = (Cache)entry.getValue();
			Set keys = cache.keys();
			for(Object key : keys) {
				Object value = cache.get(key);
				System.out.println(key+" : "+value);
			}
		}
		System.out.println("******** end of printAllCaches() **********");
		System.out.println();
		*/
		return true;
	}

	@Override
	protected boolean onAccessDenied(ServletRequest request,
			ServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}
	
	private void printAllCaches() {
		
	}

}
